﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMR.EMREditor.Src.Common;
using System.Drawing;

namespace EMR.EMREditor.Src.Document
{
    public class ZYFlag: ZYElement
    {
        public ZYFlag()
        {
            this.Type = ElementType.Flag;
        }

        Pen pen = Pens.SkyBlue;

        public override bool RefreshView()
        {
            //this.RefreshSize();
            //画标识符]
            if (!this.OwnerDocument.Info.Printing)
            {
                Point A = new Point(this.RealLeft, this.RealTop);
                Point D = new Point(this.RealLeft, this.RealTop + this.Height);
                OwnerDocument.View.DrawTriangle(A.X, A.Y, 0, this.Height / 2, this.Width, 0, Color.SkyBlue, Color.SkyBlue);
                OwnerDocument.View.DrawLine(pen, A.X, A.Y, D.X, D.Y);
            }
            return true;
        }

        public string Text
        {
            get { return myAttributes.GetString(ZYTextConst.c_Text); }
            set { myAttributes.SetValue(ZYTextConst.c_Text, value); }
        }
        //private static System.Drawing.StringFormat myMeasureFormat = null;
        //public override bool RefreshSize()
        //{
        //    if (myMeasureFormat == null)
        //    {
        //        myMeasureFormat = new System.Drawing.StringFormat(System.Drawing.StringFormat.GenericTypographic);
        //        myMeasureFormat.FormatFlags = System.Drawing.StringFormatFlags.FitBlackBox | System.Drawing.StringFormatFlags.MeasureTrailingSpaces;
        //    }

        //    if (myFont == null)
        //        myFont = myOwnerDocument.View._CreateFont
        //            ("宋体",
        //            this.FontSize,
        //            false,
        //            false,
        //            false);
        //    System.Drawing.SizeF CharSize = myOwnerDocument.View.Graph.MeasureString("_", myFont, 10000, myMeasureFormat);

        //    intWidth = (int)CharSize.Width;
        //    intHeight = (int)Math.Ceiling(myFont.GetHeight(myOwnerDocument.View.Graph));

        //    //计算宽高
        //    //this.Width = this.OwnerDocument.PixelToDocumentUnit(11)/2;
        //    //this.Height = this.OwnerDocument.DefaultRowHeight;
        //    return true;
        //}

        public override string GetXMLName()
        {
            return ZYTextConst.c_Flag;
        }

        public override bool ToXML(System.Xml.XmlElement myElement)
        {
            if (myElement != null)
            {
                myElement.SetAttribute("type", StringCommon.GetNameByType(this.Type));
                myElement.SetAttribute("name", this.Name);
                myElement.SetAttribute("code", this.Code);
                return true;
            }
            return false;
        }

        public override bool FromXML(System.Xml.XmlElement myElement)
        {
            if (myElement != null)
            {
                this.Type = StringCommon.GetTypeByName(myElement.GetAttribute("type"));
                this.Name = myElement.GetAttribute("name");
                this.Code = myElement.GetAttribute("code");
                return true;
            }
            return false;
        }

        public override string ToEMRString()
        {
            return "§";
        }
    }
}
